Source File
xtypes.go
Belonging Package
github.com/ChrisTrenkamp/goxpath/tree
package tree
import (
)
//Boolean strings
const (
True = "true"
False = "false"
)
//Bool is a boolean XPath type
type Bool bool
//ResValue satisfies the Res interface for Bool
func ( Bool) () string {
if {
return True
}
return False
}
//Bool satisfies the HasBool interface for Bool's
func ( Bool) () Bool {
return
}
//Num satisfies the HasNum interface for Bool's
func ( Bool) () Num {
if {
return Num(1)
}
return Num(0)
}
//Num is a number XPath type
type Num float64
//ResValue satisfies the Res interface for Num
func ( Num) () string {
if math.IsInf(float64(), 0) {
if math.IsInf(float64(), 1) {
return "Infinity"
}
return "-Infinity"
}
return fmt.Sprintf("%g", float64())
}
//Bool satisfies the HasBool interface for Num's
func ( Num) () Bool {
return != 0
}
//Num satisfies the HasNum interface for Num's
func ( Num) () Num {
return
}
//String is string XPath type
type String string
//ResValue satisfies the Res interface for String
func ( String) () string {
return string()
}
//Bool satisfies the HasBool interface for String's
func ( String) () Bool {
return Bool(len() > 0)
}
//Num satisfies the HasNum interface for String's
func ( String) () Num {
, := strconv.ParseFloat(strings.TrimSpace(string()), 64)
if != nil {
return Num(math.NaN())
}
return Num()
}
//NodeSet is a node-set XPath type
type NodeSet []Node
//GetNodeNum converts the node to a string-value and to a number
func ( Node) Num {
return String(.ResValue()).Num()
}
//String satisfies the Res interface for NodeSet
func ( NodeSet) () string {
if len() == 0 {
return ""
}
return [0].ResValue()
}
//Bool satisfies the HasBool interface for node-set's
func ( NodeSet) () Bool {
return Bool(len() > 0)
}
//Num satisfies the HasNum interface for NodeSet's
func ( NodeSet) () Num {
return String(.String()).Num()
}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |